package com.example.gallery;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.net.Uri;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.GridView;
import android.widget.ImageView;

import com.example.board.R;

class ImageViewHolder{
	ImageView iv;
	CheckBox checkbox;
}


public class AsyncImageListAdapter extends BaseAdapter{
	String TAG = "AsyncImageListAdapter";
	int deviceWidth;
	int deviceHeight;
	LayoutInflater inflater;
	ArrayList<ImageListDTO> list;
	Context mcontext ;	//상위 클래스로부터 context를 받음 -> imageview를 상위로 보내야 하므로
	private int mCellLayout;
	
	
	
	public AsyncImageListAdapter(Context context, ArrayList<ImageListDTO> list) {
		this.mcontext = context;
		this.list = list;
		DisplayMetrics displayMetrics = new DisplayMetrics();
		
		deviceWidth = displayMetrics.widthPixels;
		deviceHeight = displayMetrics.heightPixels;
//		getCount();
	}
	
	
	
	@Override
	public int getCount() {
		int count = 0;
		count = list.size();
//		Log.i(TAG, "리스트 수 : "+count+"");
		return count;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		Log.i(TAG, "getItem : ["+position+"]" +list.get(position));
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}
	
	/*
	 * public static class ViewHolder{
		public ImageView imageview;
	}
	*/
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
//		Create a new LayoutInflater 
		LayoutInflater inflater = (LayoutInflater) mcontext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View gridView;	
		gridView = null;
		convertView = null;		//avoids recycling of grid view
			
		if(convertView == null){
			gridView = new View(mcontext);

//			inflating grid view item
			gridView = inflater.inflate(R.layout.image_row, null);
			ImageViewHolder holder = new ImageViewHolder();
			
			
			holder.iv = (ImageView) gridView.findViewById(R.id.iv_image);
//			imageView.setLayoutParams(new GridView.LayoutParams(70, 70));
//			setImageURI(Uri.parse(list.get(position).getData()));
//			Log.i(TAG, list.get(position).a_image );
		}
		

		return gridView;
	}


}
